// pages/list/index.js
Page({
  data: {
    list: [],
    total: 0,
    pages: 0//当前第几页
  },
  onLoad () {
    wx.startPullDownRefresh()
  },
  async onPullDownRefresh () {

    await this.loadNoce();
  },
  async loadNoce () {
    wx.showNavigationBarLoading()
    wx.showLoading({
      title: '刷新中',
    })
    this.setData({
      list: [],
      total: 0,
      pages: 0
    });
    await this.loadMore()

  },
  async loadMore () {
    wx.showNavigationBarLoading()
    wx.showLoading({
      title: '刷新中',
    })
    let pages = this.data.pages;
    const data = await getApp().httpModule.getList(pages);
    wx.hideLoading();
    wx.stopPullDownRefresh();
    wx.hideNavigationBarLoading();
    let list = data.data.data;
    const listData = this.data.list;
    for (let i in list) {
      listData.push(list[i])
    }
    //
    console.log(listData)
    listData.forEach(item=>{
     console.log(item,'这里吗')
      if(item.locationName==null){
        item.locationName = "暂无签到地址"
      }
     if(item.locationName){
  
      try {
        item.locationName = JSON.parse(item.locationName)
      } catch (error) {
        item.locationName =item.locationName
      }
     }
      // item.locationName = JSON.parse(item.locationName)
    })
    const total = list[0]?list[0].total:0;

    this.setData({ list: listData, total });
    console.log(this.data.list)

  },
  pImage (e) {
    console.log(e)
    const index = parseInt(e.currentTarget.dataset.e)
    const list = this.data.list;
    const urls = [];
    for (let i in list) {
      urls.push(list[i].fileName)
    }
    wx.previewImage({
      urls,
      current: urls[index]
    })
  },
  async onReachBottom () {
    let pages = this.data.pages;
    const total = this.data.total;
    console.log(pages, total)
    console.log((pages + 1) * 4 < total)
    if ((pages + 1) * 4 < total) {
      pages++;
      this.setData({ pages })
      await this.loadMore()
    }
  }
})